import request from '@/utils/request'
import { urlPrefix } from './config'
import { formatQuery } from './util'
import qs from 'qs'

export function getWaitingList(query, job_id) {
  if (job_id) {
    query.job_id = job_id
    const queryString1 = qs.stringify(query)
    return request({
      url: `${urlPrefix}/interview/waiting_quick?${queryString1}`,
      method: 'get'
    })
  } else {
    const queryString2 = qs.stringify(query)
    return request({
      url: `${urlPrefix}/interview/waiting?${queryString2}`,
      method: 'get'
    })
  }
}

export function getWaitingListQuick(page = 1, job_id) {
  return request({
    url: `${urlPrefix}/interview/waiting_quick?page=${page}&job_id=${job_id}`,
    method: 'get'
  })
}

export function updateWaiting(id, data) {
  return request({
    url: `${urlPrefix}/interview/waiting/update/${id}`,
    method: 'patch',
    data
  })
}

export function getFirstList(page = 1, query) {
  let url = `${urlPrefix}/interview/first?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getSecondList(page = 1, query) {
  let url = `${urlPrefix}/interview/second?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getHrList(page = 1, query) {
  let url = `${urlPrefix}/interview/hr?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getHrListA(page = 1, query) {
  let url = `${urlPrefix}/interview/hr_a?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getHrListB(page = 1, query) {
  let url = `${urlPrefix}/interview/hr_b?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getHrListC(page = 1, query) {
  let url = `${urlPrefix}/interview/hr_c?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getOfferSuccessList(page = 1, query) {
  let url = `${urlPrefix}/interview/success?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function backTalentPool(id) {
  const data = {}
  return request({
    url: `${urlPrefix}/interview/waiting/back_pool/${id}`,
    method: 'patch',
    data
  })
}

export function firstComment(id, data) {
  return request({
    url: `${urlPrefix}/interview/first/update/${id}`,
    method: 'patch',
    data
  })
}

export function secondComment(id, data) {
  return request({
    url: `${urlPrefix}/interview/second/update/${id}`,
    method: 'patch',
    data
  })
}

export function sendFirst(id, time, group) {
  const data = { interview_status: 1, time: time, group: group }
  return request({
    url: `${urlPrefix}/talent/send_first_interview/${id}`,
    method: 'patch',
    data
  })
}

export function sendSecond(id, time, group) {
  const data = { interview_status: 1, time: time, group: group }
  return request({
    url: `${urlPrefix}/talent/send_second_interview/${id}`,
    method: 'patch',
    data
  })
}

export function getWaitingSecondList(page = 1, query) {
  let url = `${urlPrefix}/interview/waiting_second?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function getWaitingHrList(page = 1, query) {
  let url = `${urlPrefix}/interview/waiting_hr?page=${page}`
  if (query) {
    query = formatQuery(query)
    url += `&${query}`
  }
  return request({
    url: url,
    method: 'get'
  })
}

export function lastHrComment(data) {
  return request({
    url: `${urlPrefix}/interview/hr/update/${data.id}`,
    method: 'patch',
    data
  })
}

export function lastHrAComment(data) {
  return request({
    url: `${urlPrefix}/interview/hr_a/update/${data.id}`,
    method: 'patch',
    data
  })
}

export function lastHrBComment(data) {
  return request({
    url: `${urlPrefix}/interview/hr_b/update/${data.id}`,
    method: 'patch',
    data
  })
}

export function lastHrCComment(data) {
  return request({
    url: `${urlPrefix}/interview/hr_c/update/${data.id}`,
    method: 'patch',
    data
  })
}
